package top.kpromise.note.modules.todo.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import top.kpromise.common.base.BaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.io.Serializable;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@Entity(name = "to_do")
@org.hibernate.annotations.Table(appliesTo = "to_do", comment = "待办表")
@Table(name = "to_do")
@DynamicInsert
@DynamicUpdate
public class ToDoEntity extends BaseEntity implements Serializable {

    @ApiModelProperty(name = "title", value = "标题")
    @Column(columnDefinition = "VARCHAR(1024) comment '标题'")
    private String title;

    @ApiModelProperty(name = "content", value = "内容")
    @Column(columnDefinition = "VARCHAR(2048) comment '内容'")
    private String content;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "deadline", columnDefinition = "datetime comment '最后期限'")
    @ApiModelProperty(name = "deadline", value = "最后期限")
    private Date deadline;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "finish_at", columnDefinition = "datetime comment '完成日期'")
    @ApiModelProperty(name = "finishAt", value = "完成日期")
    private Date finishAt;

    @ApiModelProperty(name = "id", value = "用户ID")
    @Column(nullable = false, columnDefinition = "BIGINT comment '用户ID'")
    private Long userId;

    @Min(1)
    @Max(3)
    @ApiModelProperty(name = "state", value = "当前状态，1-新建，2-进行中，3-完成")
    @Column(columnDefinition = "tinyint default 1 comment '当前状态，1-新建，2-进行中，3-完成'")
    private Integer state;

    @Min(1)
    @Max(4)
    @ApiModelProperty(name = "priority", value = "优先级，1-普通，2-中优先级，3-高优先级，4-紧急")
    @Column(columnDefinition = "tinyint default 1 comment '优先级，1-普通，2-中优先级，3-高优先级，4-紧急'")
    private Integer priority;

    @Transient
    public static final int STATE_FINISHED = 3;

    @Transient
    public static final int STATE_ON_GOING = 2;

    @Transient
    public static final int STATE_CREATED = 1;
}
